<template>
	<el-dialog :title="titles" v-model="dialogPush" class="dialog-push">
		<div style="margin:10px 0;">
			<el-button type="primary" v-on:click="pushSubmit"><i class="el-icon-circle-check el-icon--left"></i>{{$t('message.submitPush')}}</el-button>
			<span class="require-icon"></span>
			<el-input style="width: 50%" v-model="pushInfor" @blur="checkEmpty" :class="{'empty-error':pushInforEmpty}" :placeholder="$t('message.inputTheReasonForPush')"></el-input><span style="color:#f34b4b;margin-left:5px;" v-show="pushInforEmpty">{{$t('message.reasonForPushIsRequird')}}</span>
		</div>
		<section class="tree_list">
			<p class="panel_title">{{listTitle}}</p>
			<!-- <div style="margin-top: 5px;" v-if="pushData.length > 0" v-for="item in pushData">
				<el-radio style="margin-top: 5px" class="radio" v-model="radio" :label="item">{{item.name}}（{{item.desc}}）</el-radio>
			</div>
			<div v-if="pushData.length == 0" style="padding-top: 15px;text-align: center">
				<el-tag type="danger">暂无与该设备匹配的升级文件</el-tag>
			</div> -->
			<el-table border style="width: 100%;" :data="pushData">
				<el-table-column label="" width="50">
					<template slot-scope="scope">
						<el-radio :label="scope.row" v-model="radio" @change.native="getCurrentRow(scope.row)">&nbsp;</el-radio>
					</template>
				</el-table-column>
				<el-table-column :show-overflow-tooltip="true" label="名称" align="center" prop="name">
				</el-table-column>
				<el-table-column :show-overflow-tooltip="true" label="是否存在" align="center">
					<template slot-scope="scope">
						<el-tag type="success" v-if="scope.row.existed">存在</el-tag>
						<el-tag type="danger" v-else>不存在</el-tag>
					</template>
				</el-table-column>
				<el-table-column :show-overflow-tooltip="true" label="上传时间" align="center" prop="time" width="200"></el-table-column>
				<el-table-column :show-overflow-tooltip="true" label="描述" align="center" prop="desc"></el-table-column>
			</el-table>
		</section>
	</el-dialog>
</template>
<script>
	import $ from 'jquery'
	import { GloabFun } from '../assets/js/common.js'

	export default {
		data() {
			return {
				dialogPush: false,
				pushInforEmpty: false,
				pushInfor: '',
				pushItemId: '',
				pushItemType: '',
				AndroidConfigId: '',
				radio: {}
			}
		},
		props: {
			pushData: {
				type: Array,
				default: []
			},
			props: {
				type: Object,
				require: true
			},
			titles: {
				type: String,
				require: true
			},
			listTitle: {
				type: String,
				require: true
			},
			selectWarning:{
				type: String,
				require: true
			}
		},
		methods: {
			pushSubmit() {
				if(!this.checkEmpty()) {
					if(JSON.stringify(this.radio) != "{}"){
						this.pushLoading = true;
						this.$emit("pushSubmit", {
							data: this.radio,
							Reason: this.pushInfor
						});
					}else{
						this.$message({
							message: this.selectWarning,
							type: 'error'
						});
					}
				} else {
				}
			},
			checkEmpty() {
				if(GloabFun.trim(this.pushInfor).length > 0) {
					this.pushInforEmpty = false;
					return false;
				} else {
					this.pushInforEmpty = true;
					return true;
				}
			},
			getCurrentRow(row) {
				// this.radio = row;
			},
			showDialog() {
				this.dialogPush = true;
			},
			closeDialog() {
				this.dialogPush = false;
				this.pushInfor = '';
			},
			contain(array, id) {
				for(var i = 0; i < array.length; i++) {
					if(array[i] === id) {
						return true
					}
				}
				return false;
			}
		},
		created() {
			if(this.pushData.length > 0){
				this.radio = this.pushData[0];
			}
			this.$nextTick(function() {
				$(".push-dialog-tree").find("input").removeAttr("disabled");
			});
		}
	}
</script>
<style lang="less">
	/* .push-dialog-tree{
       input
   } */
</style>
<style scoped>
	.require-icon::before {
		content: '*';
		color: #f34b4b;
		margin-right: 4px;
		margin-left: 20px;
	}
</style>